package forward.Module.Modules.Combat;

import forward.Client;
import forward.Module.Module;
import forward.Module.ModuleType;
import forward.UI.ClientNotification;
import forward.Util.ClientUtil;
import forward.api.EventHandler;
import forward.api.Events.World.EventPacketSend;
import forward.api.Value.Mode;
import io.netty.buffer.Unpooled;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.C17PacketCustomPayload;

import java.awt.*;

public class ClientSpoofer extends Module {
    public static Mode mode = new Mode("Mode", "mode", (Enum[])SpoofMode.values(), (Enum)SpoofMode.Lunar);

    public ClientSpoofer() {
        super("ClientSpoofer", new String[]{"ClientSpoofer"}, ModuleType.Combat);
        this.addValues(mode);
    }
    // private final ModeSetting mode = new ModeSetting("Mode", this, "Forge", "Forge", "Lunar", "LabyMod", "PvP Lounge", "CheatBreaker", "Geyser");


    public void onEnable() {
        ClientUtil.sendClientMessage("Rejoin For ClientSpoofer to work.", ClientNotification.Type.SUCCESS);
       // this.registerNotification("Rejoin for " + this.getModuleInfo().name() + " to work.");
    }

    @EventHandler
    public void onPacketSend(EventPacketSend event) {
        if (event.getPacket() instanceof C17PacketCustomPayload) {
            final C17PacketCustomPayload packet = (C17PacketCustomPayload) event.getPacket();
            if (mode.getValue()==SpoofMode.Forge) {
                packet.data = createPacketBuffer("FML", true);
            } else if (mode.getValue()==SpoofMode.Lunar) {
                packet.channel = ("REGISTER");
                packet.data = (createPacketBuffer("Lunar-Client", false));
            } else if (mode.getValue()==SpoofMode.LabyMod) {
                packet.data = (createPacketBuffer("LMC", true));
            } else if (mode.getValue()==SpoofMode.PvPLounge) {
                packet.data = (createPacketBuffer("PLC18", false));
            } else if (mode.getValue()==SpoofMode.CheatBreaker) {
                packet.data = (createPacketBuffer("CB", true));
            } else if (mode.getValue()==SpoofMode.Geyser) {
                packet.data = (createPacketBuffer("Geyser", false));
            }
        }
    }

    private PacketBuffer createPacketBuffer(final String data, final boolean string) {
        if (string)
            return new PacketBuffer(Unpooled.buffer()).writeString(data);
        else
            return new PacketBuffer(Unpooled.wrappedBuffer(data.getBytes()));
    }
    enum SpoofMode {
        Forge,Lunar, LabyMod, PvPLounge, CheatBreaker, Geyser;
    }
}
